//
//  MoodShareViewController.m
//  UESTCPioneer
//
//  Created by Sway on 14-3-5.
//  Copyright (c) 2014年 Sway. All rights reserved.
//

#import "MoodShareViewController.h"
#import "UPTableView.h"
#import "UPTitleCell.h"
#import "UPMainInfoCell.h"
#import "UPFooterCell.h"
#import "LeveyTabBarController.h"
#import "MoodShareNewsEntity.h"
#import "StartActivity.h"
#import "ActivityShareController.h"

//#define MoodShareMapping @{@"commentNum":@"numberOfComment"\
//                            ,@"content":@"newsBody"\
//                            ,@"id":@"theId"\
//                            ,@"picUrl":@"picUrl"\
//                            ,@"time":@"timeAndDate"\
//                            ,@"userId":@"userId"\
//                            ,@"userName":@"titleBody"\
//}

#define requestTestData @{@"type":@"getEventShare",@"userId":@"0010013110361",@"page":@"1"}

#define MoodShareEntityName @"MoodShareNewsEntity"


#define normalCommitButtonColor [UIColor colorWithRed:170.0/255.0 green:170.0/255.0 blue:170.0/255.0 alpha:1]




#pragma mark - EditShareViewController
@interface EditShareViewController:StartActivity{
    UILabel *_titleLabel;
    UITextView *writeRect;
}

@property NSString *shareTitle;

@end
@implementation EditShareViewController

-(void)viewDidLoad{
    [super viewDidLoad];
    
    isFirstEdit1=NO;
    
    
    //隐藏默认返回按钮
    [self.navigationItem setHidesBackButton:YES];
    //修改标题
    self.navigationItem.title=@"编辑分享";
    [self.view setBackgroundColor:ViewControllerBackgroundColor];
    
    
    //修改背景色为白色
    [self.navigationController.navigationBar setBarTintColor:[UIColor whiteColor]];
    //修改字体为红色
    [self.navigationController.navigationBar setTintColor:kNavigationBarColor];
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:kNavigationBarColor}];
    
    //修改顶部运营商和时间为黑色
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
    
    //修改左边button
    UIBarButtonItem *leftBarButton  =[[UIBarButtonItem alloc]initWithTitle:@"取消" style:UIBarButtonItemStylePlain target:self action:@selector(pop:)];
    [self.navigationItem setLeftBarButtonItem:leftBarButton];
    //    [leftBarButton setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor grayColor]} forState:UIControlStateNormal];
    
    
    UIBarButtonItem *rightBarButton  = [[UIBarButtonItem alloc]initWithTitle:@"发表" style:UIBarButtonItemStylePlain target:self action:@selector(commitShare:)];
    [self.navigationItem setRightBarButtonItem:rightBarButton];
    [rightBarButton setTitleTextAttributes:@{NSForegroundColorAttributeName:normalCommitButtonColor} forState:UIControlStateNormal];
    
    
    
    self.editTitle.editable=NO;
    self.editTitle.text=_shareTitle;
    [self.editTitle setTextColor:[UIColor blackColor]];
    
    //#pragma mark 标题栏
    //    _titleLabel=[[UILabel alloc]init];
    //    [self.view addSubview:_titleLabel];
    //    [_titleLabel setTranslatesAutoresizingMaskIntoConstraints:NO];
    //    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-20-[_titleLabel(==30)]" options:0 metrics:Nil views:NSDictionaryOfVariableBindings(_titleLabel)]];
    //    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-10-[_titleLabel]-10-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_titleLabel)]];
    //    _titleLabel.text=@"  支部生活有你我";
    //    [_titleLabel.layer setBorderColor:kBorderColor.CGColor];
    //    [_titleLabel.layer setBorderWidth:1];
    //    [_titleLabel.layer setCornerRadius:4];
    //    [_titleLabel setBackgroundColor:[UIColor whiteColor]];
    //
    //#pragma mark 书写栏
    //    writeRect = [[UITextView alloc]init];
    //    [self.view addSubview:writeRect];
    //    [writeRect setTranslatesAutoresizingMaskIntoConstraints:NO];
    //    [writeRect.layer setBorderColor:kBorderColor.CGColor];
    //    [writeRect.layer setBorderWidth:1];
    //    [writeRect.layer setCornerRadius:4];
    //    [writeRect setBackgroundColor:[UIColor whiteColor]];
    //    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[_titleLabel]-10-[writeRect(==160)]" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_titleLabel,writeRect)]];
    //    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-10-[writeRect]-10-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(writeRect)]];
    //    [writeRect setFont:[UIFont systemFontOfSize:18]];
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationItem.title=@"编辑分享";
    //    self.editBody.text = @"请输入体验分享的内容...";
}

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    //还原顶部设置
    [self.navigationController.navigationBar setBarTintColor:kNavigationBarColor];
    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
    [self.navigationItem setHidesBackButton:NO];
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
    
    //-(void)viewDidDisappear:(BOOL)animated{
    //    [[UINavigationBar appearance]setBarTintColor:kNavigationBarColor];
    //    [self.navigationController.navigationBar setBarTintColor:];
}

#pragma mark - pop button
-(void)pop:(UIButton*)button{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - commit share
-(void)commitShare:(id)sender{
    /*修改*/
    //    self.editBody.text = [NSString stringWithFormat:@"[%@]\n%@",self.editTitle.text,self.editBody.text];
    
    /**/
    NSDictionary *requestD = @{@"userId":[constant getUserId]
                               ,@"eventTitle":[helper urlencode:self.editTitle.text]
                               ,@"userName":[constant getUserName]
                               ,@"content":[helper urlencode:self.editBody.text]
                               ,@"type":@"EventShare"
                               };
    
    [NetworkCenter requestActivity:requestD ImageArray:[self getPickedImageArray] SuccessBlock:^(id resultObject) {
        NSDictionary *dic= [NSJSONSerialization JSONObjectWithData:resultObject options:NSJSONReadingMutableLeaves error:Nil];
        if ([dic[@"result"] isEqualToString:@"success"]){
            [self.navigationController popToRootViewControllerAnimated:YES];
            
            [helper performBlock:^{
                MoodShareViewController *m= (MoodShareViewController*)self.leveyTabBarController.selectedViewController;
                [m.tableView beginRefreshing];
            } afterDelay:0.45];
        }
        else {
            [Alert showAlert:@"发生错误"];
        }
    } failure:^(NSError *error) {
        [Alert showAlert:@"发生错误"];
    }];
}


-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    [writeRect resignFirstResponder];
}

@end


#pragma mark - SelectTableView
@interface SelectTableView :UITableView
@end

@implementation SelectTableView

//-(void)setFrame:(CGRect)frame{
//    frame.origin.y+=10;
//    frame.origin.x+=16;
//    frame.size.width-=32;
//}
@end





#pragma mark - SelectShareViewCotroller

@interface SelectShareViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>{
    UITextField *searchField;
    SelectTableView *_tableView;
    NSLayoutConstraint *tableViewHeightConstraint;
    NSArray *titleArrayForDataSoruce;
}

@end

@implementation SelectShareViewController

-(void)viewDidLoad{
    [self.view setBackgroundColor:ViewControllerBackgroundColor];
    
#pragma mark 顶部搜索栏
    //背景
    UIView *topRect = [[UIView alloc]init];
    [self.view addSubview:topRect];
    [topRect setBackgroundColor:[UIColor whiteColor]];
    [topRect setTranslatesAutoresizingMaskIntoConstraints:NO];
    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-(-1)-[topRect]-(-1)-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(topRect)]];
    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-(-1)-[topRect(==44)]" options:0 metrics:nil views:NSDictionaryOfVariableBindings(topRect)]];
    [topRect.layer setBorderColor:kBorderColor.CGColor];
    [topRect.layer setBorderWidth:1];
    //搜索栏
    searchField = [[UITextField alloc]init];
    
    
    //搜索栏改变
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(searchTextChangeNotification:) name:UITextFieldTextDidChangeNotification object:searchField];
    
    [topRect addSubview:searchField];
    [searchField.layer setBorderWidth:1];
    [searchField.layer setBorderColor:kBorderColor.CGColor];
    [searchField setBackgroundColor:ViewControllerBackgroundColor];
    [searchField setTranslatesAutoresizingMaskIntoConstraints:NO];
    [topRect addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-16-[searchField]-16-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(searchField)]];
    [topRect addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-8-[searchField]-8-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(searchField)]];
    [searchField setPlaceholder:@"请选择一个活动"];
    
#pragma mark TableView
    _tableView=[[SelectTableView alloc]init];
    [self.view addSubview:_tableView];
    [_tableView setTranslatesAutoresizingMaskIntoConstraints:NO];
    //    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-10-[_tableView]-10-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_tableView)]];
    //    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[topRect]-8-[_tableView]-8|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_tableView,topRect)]];
    
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:_tableView
                                                          attribute:NSLayoutAttributeTop
                                                          relatedBy:NSLayoutRelationEqual
                                                             toItem:topRect
                                                          attribute:NSLayoutAttributeBottom
                                                         multiplier:1 constant:8]];
    
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:_tableView
                                                          attribute:NSLayoutAttributeLeft
                                                          relatedBy:NSLayoutRelationEqual
                                                             toItem:self.view
                                                          attribute:NSLayoutAttributeLeft
                                                         multiplier:1 constant:10]];
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:_tableView
                                                          attribute:NSLayoutAttributeRight
                                                          relatedBy:NSLayoutRelationEqual
                                                             toItem:self.view
                                                          attribute:NSLayoutAttributeRight
                                                         multiplier:1 constant:-10]];
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:_tableView
                                                          attribute:NSLayoutAttributeBottom
                                                          relatedBy:NSLayoutRelationEqual
                                                             toItem:self.view
                                                          attribute:NSLayoutAttributeBottom
                                                         multiplier:1 constant:-8]];
    
    
    
    
    
    
    
    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[_tableView(==300)]" options:0 metrics:Nil views:NSDictionaryOfVariableBindings(_tableView)]];
    //    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[_tableView(==21)]" options:0 metrics:Nil views:NSDictionaryOfVariableBindings(servicesBtn)]];
    //    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-10-[_tableView]-10-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_tableView)]];
    //    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[topRect]-8-[_tableView]-8|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_tableView,topRect)]];
    //    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:_tableView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationGreaterThanOrEqual toItem:self.view attribute:NSLayoutAttributeBottom multiplier:1 constant:-40]];
    
    tableViewHeightConstraint=[NSLayoutConstraint constraintWithItem:_tableView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:0];
    
    //    tableViewHeightConstraint=[NSLayoutConstraint constraintWithItem:_tableView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeHeight multiplier:1 constant:];
    //    [self.view addConstraint:tableViewHeightConstraint];
    
    _tableView.delegate=self;
    _tableView.dataSource=self;
    
    [_tableView.layer setBorderColor:kBorderColor.CGColor];
    [_tableView.layer setBorderWidth:1];
    [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    
    
    
    [self doSearchTitle:@""];
}





-(void)viewWillAppear:(BOOL)animated{
    self.navigationItem.title=@"选择活动";
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    [searchField resignFirstResponder];
}

#pragma mark - tableView delegate
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    int i = 8;
    NSInteger row=[titleArrayForDataSoruce count];
    if([[UIScreen mainScreen] bounds].size.height > 480){
        i = 10;
    }
    
    
    if (row>10)tableViewHeightConstraint.constant=44*i;
    else tableViewHeightConstraint.constant=row*44;
    return row;
}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    cell.textLabel.text=titleArrayForDataSoruce[indexPath.row];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    //    EditShareViewController *editShare = [[EditShareViewController alloc]initWithStyle:UITableViewStyleGrouped];
    ActivityShareController  *editShare = [[ActivityShareController alloc]initWithStyle:UITableViewStyleGrouped];
    editShare.shareTitle=titleArrayForDataSoruce[indexPath.row];
    //    [self.navigationController presentViewController:editShare animated:YES completion:NULL];
    [self.navigationController pushViewController:editShare animated:YES];
    [searchField resignFirstResponder];
}

#pragma mark - do search title
//发请求，通过关键字请求活动标题列表
-(void)doSearchTitle:(NSString*)title{
    //222.197.183.81:8080/ScienceApp/ieaction.do?type=searchTitle&userId=0012005130022&title=
    
    NSDictionary *RequestD = @{@"type":@"searchTitle"
                               ,@"userId":[constant getUserId]
                               ,@"title":title};
    
    [NetworkCenter AFRequestWithData:RequestD SuccessBlock:^(AFHTTPRequestOperation *operation, id resultObject) {
        NSArray *dic = [NSJSONSerialization JSONObjectWithData:resultObject options:NSJSONReadingMutableLeaves error:nil];
        NSMutableArray *mut = [[NSMutableArray alloc] init];
        for (NSDictionary *dicItem in dic){
            [mut addObject:dicItem[@"title"]];
        }
        
        titleArrayForDataSoruce=[[NSArray alloc]initWithArray:mut];
        [_tableView reloadData];
        
        
    } FailureBlock:^(AFHTTPRequestOperation *operation, NSError *error) {
        
    }];
}

#pragma mark - searchText Change Notification
-(void)searchTextChangeNotification:(NSNotification*)notify{
    UITextField *textField = [notify object];
    [self doSearchTitle:textField.text];
}

@end

#pragma mark - MoodShareViewController
#pragma mark - 颜色
#define kNavigationBarColor [UIColor colorWithRed:192.0/255.0 green:57.0/255.0 blue:43.0/255.0 alpha:1]
#define KSPEColor [UIColor colorWithRed:204.0/255.0 green:204.0/255.0 blue:204.0/255.0 alpha:1]
#define KBtnTextColor [UIColor colorWithRed:119.0/255.0 green:119.0/255.0 blue:119.0/255.0 alpha:1]
#import "PartyActivityViewController.h"
@interface MoodShareViewController (){
    UIButton *lawGuideBtn;
    UIButton *freshmenGuideBtn;
    UIView *slideBar;
}

@end

@implementation MoodShareViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    UnreadKey=kUnreadMoodShare;
    
    tableViewTopConstraint.constant = 48;
    
    [self hideTopView];
    //        tableViewTopConstraint.constant=0;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    
    [self addHeadView];
    
    
    //    [self.tableView setPullDownBeginRefreshAction:@selector(refreshRequest:) ];
    
    
    
#pragma mark request Data load
    entityName=kMoodShareNewsEntityName;
    entityMapping=[Mapping MoodShareMapping];
    requestData=@{@"type":@"getEventShare",@"userId":[constant getUserId],@"page":@"1"};
    //请求评论列表用的参数
    commentListRequestData=@{@"type":@"getShareComment",@"page":@"1",@"shareId":@"0"};
    //写评论请求用的参数
    commentWriteRequestData=@{@"type":@"writeShareComment",@"userId":[constant getUserId],@"userName":[constant getUserName],@"shareId":@"0",@"comment":@""};
    commentIdKey=@"shareId";
    commentContentKey=@"comment";
    commentWriteIdKey=commentIdKey;
    commentListKeyMapping=@{@"commentAuthor":@"userName",@"commentContent":@"commentBody",@"commentDate":@"commentDate"};
    
    commentFlag = @"MoodShare";
}
#pragma mark -
#pragma mark 初始化
-(void)addHeadView{
    UIView *headView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 47)];
    headView.backgroundColor = [UIColor whiteColor];
    
    UIView *barLine = [[UIView alloc] initWithFrame:CGRectMake(0, 47, 320,1)];
    barLine.backgroundColor = KSPEColor;
    [headView addSubview:barLine];
    
    lawGuideBtn = [self addBtn:CGRectMake(0, 0, 320/2, 47) title:@"组织活动" tag:1 normalColor:KBtnTextColor];
    [headView addSubview:lawGuideBtn];
    
    freshmenGuideBtn = [self addBtn:CGRectMake(320/2, 0, 320/2, 47) title:@"体验分享" tag:2 normalColor:kNavigationBarColor];
    [headView addSubview:freshmenGuideBtn];
    
    slideBar = [[UIView alloc] initWithFrame:CGRectMake(0, 43, 320/2, 4)];
    slideBar.backgroundColor = kNavigationBarColor;
    [headView addSubview:slideBar];
    
    [self.view addSubview:headView];
}

//1.添加按钮
-(UIButton *)addBtn:(CGRect)rect title:(NSString*)title tag:(NSInteger)tag normalColor:(UIColor*)color{
    UIButton *btn = [[UIButton alloc] initWithFrame:rect];
    [btn setTitle:title forState:UIControlStateNormal];
    btn.tag = tag;
    [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    [btn setTitleColor:kNavigationBarColor forState:UIControlStateHighlighted];
    [btn setTitleColor:color forState:UIControlStateNormal];
    return btn;
}
//2.按钮点击
-(void)btnClick:(UIButton*)btn{
    
    if (btn.tag == 1) {
        PartyActivityViewController *shareContr = [[PartyActivityViewController alloc] init];
        
        [self.leveyTabBarController removeViewControllerAtIndex:0];
        [self.leveyTabBarController setSelectedIndex:1];
        
        [shareContr willMoveToParentViewController:self.leveyTabBarController];
        [self.leveyTabBarController insertViewController:shareContr  atIndex:0];
        [self.revealSideViewController popViewControllerWithNewCenterController:[constant getCenterController] animated:YES];
        [self.leveyTabBarController setSelectedIndex:0];
        [shareContr didMoveToParentViewController:[constant getCenterController]];
    }
    
}

//3.滑条动画
-(void)Animation:(int)selelctTag{
    CGRect newFram = slideBar.frame;
    newFram = CGRectMake(selelctTag * 320/2, 43, 320/2, 4);
    [UIView beginAnimations:@"slide" context:nil];
    [UIView setAnimationDuration:0.40];
    [slideBar setFrame:newFram];
    [UIView commitAnimations];
}
-(void)viewDidAppear:(BOOL)animated{
    [self Animation:1];
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.leveyTabBarController.navigationItem setTitle:@"党员活动"];
    
    UIButton *writeButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [writeButton setImage:[UIImage imageNamed:@"write.png"] forState:UIControlStateNormal];
    [writeButton setImageEdgeInsets:UIEdgeInsetsMake(10, 22, 5, 20)];
    [writeButton addTarget:self action:@selector(writeButtonPress:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *barButton=[helper BarButtonItemWithUIButton:writeButton ButtonOrigin:CGPointMake(10, 0)];
    //@判断是否为管理员
    NSString *userId=[constant getUserId];
    
//    NSString *lastChar =[userId substringFromIndex:[userId length]-1];
    
    /*修改*/
    self.isMoodShare = YES;
    /**/
    /* 任何人都需要分享
     if (([lastChar isEqualToString:@"1"] || [lastChar isEqualToString:@"2"])){
     [self.leveyTabBarController.navigationItem setRightBarButtonItem:barButton];
     }
     */
    [self.leveyTabBarController.navigationItem setRightBarButtonItem:barButton];
    
    
}

-(void)viewWillDisappear:(BOOL)animated{
    [self.leveyTabBarController.navigationItem setRightBarButtonItem:nil];
}

//每个分区的行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 3;
}

//表的分区数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return [tableViewEntitiesArray count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewCell *cell=[super tableView:tableView cellForRowAtIndexPath:indexPath];
    
    
    if (indexPath.row == 0) {
        //        static NSString *customTitleCellIndentifier = @"CustomTitleCellIndentifier";
        //        UPTitleCell *cell = [tableView dequeueReusableCellWithIdentifier:customTitleCellIndentifier];
        //        if(cell == nil){
        //            cell = [[UPTitleCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:customTitleCellIndentifier];
        //        }
        //        UIImageView *img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"default_head_image.png"]];
        //        img.frame = CGRectMake(5, 5, 45, 45);
        //        [cell.contentView addSubview:img];
        //        UILabel *title = (UILabel *)[cell.contentView viewWithTag:titleTag];
        //        title.frame = CGRectMake(60, 10, 250, 20);
        //        title.text = DataEntity.titleBody;
        //        UILabel *time = (UILabel *)[cell.contentView viewWithTag:timeTag];
        //        time.frame = CGRectMake(60, 30, 250, 20);
        //        time.text = [DataEntity.timeAndDate description];
        UPTitleCell *cell1 = (UPTitleCell*)cell;
        return cell1;
    }
    else if (indexPath.row == 1) {
        //        static NSString *customMainCellIndentifier = @"CustomMainCellIndentifier";
        //        UPMainInfoCell *cell2 = [tableView dequeueReusableCellWithIdentifier:customMainCellIndentifier];;
        //        if(cell2 == nil){
        //            cell2 = [[UPMainInfoCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:customMainCellIndentifier];
        //        }
        //        UILabel *words = (UILabel *)[cell2.contentView viewWithTag:wordsTag];
        ////        words.text = @"在讨论这部纪录片之前，为了避免现在中文网络江湖盛行的动机论，我先要说明：我和崔永元老师没有个人恩怨，相反，对他的主持功力和以前取得的成绩都非常钦佩。我们也至少有一名共同的好朋友，《读库》的出版人张立宪。";
        //        words.text=DataEntity.newsBody;
        //        return cell2;
        UPMainInfoCell *cell2= (UPMainInfoCell*)cell;
        
        return cell2;
    }
    else {
        //        static NSString *customFooterCellIndentifier = @"CustomFooterCellIndentifier";
        //        UPFooterCell *cell3 = [tableView dequeueReusableCellWithIdentifier:customFooterCellIndentifier];;
        //        if(cell3 == nil){
        //            cell3 = [[UPFooterCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:customFooterCellIndentifier];
        //        }
        //
        //
        //
        //        commentButton *btn3 = (commentButton *)[cell3.contentView viewWithTag:btn3Tag];
        //        [btn3 setTitle:[NSString stringWithFormat:@"%d",[DataEntity.numberOfComment integerValue]] forState:UIControlStateNormal];
        //        btn3.theId=[DataEntity.theId integerValue];
        //
        //        [btn3 addTarget:self action:@selector(commentButtonPress:) forControlEvents:UIControlEventTouchUpInside];
        UPFooterCell *cell3 = (UPFooterCell*)cell;
        //        UIButton *btn1 = (UIButton *)[cell3.contentView viewWithTag:btn1Tag];
        //        UIButton *btn2 = (UIButton *)[cell3.contentView viewWithTag:btn2Tag];
        
        //        btn1.hidden = NO;
        //        btn2.hidden = NO;
        
        
        [cell3 addCommentButtonTaget:self Action:@selector(commentButtonPress:)];
        return cell3;
    }
    
}

//修改行高度的位置
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return [super tableView:tableView heightForRowAtIndexPath:indexPath];
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 5;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    // indexPath.section,根据分组进行更精确的配置
    return 5;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark -  pull Refresh



#pragma mark - commentButton press



#pragma mark - writeButtonPress
-(void)writeButtonPress:(UIButton*)button{
    
    SelectShareViewController *edit = [[SelectShareViewController alloc]init];
    [self.leveyTabBarController.navigationController pushViewController:edit animated:YES];
}



/*重写父类方法*/
//-(void)WholeNewsButtonClick:(NSInteger)theId{
//    BOOL result = [self ScreenTouch];
//    if (result) {
//        return;
//    }
//    
//    MoodShareNewsEntity *entity = [PublicMethod entity:kMoodShareNewsEntityName WithId:theId];
//    NSString *title = entity.eventTitle;
//    NSString *content;
//    NSRange  range;
//    range = [entity.newsBody rangeOfString:@"]"];
//    if (range.location != NSNotFound) {
//        content = [entity.newsBody substringFromIndex:range.location+2];
//        
//    }else{
//        
//    }
//    
//    UIViewController *viewController = [[UIViewController alloc]init];
//    
//    [viewController.view setFrame:self.view.frame];
//    [viewController.view setBackgroundColor:[UIColor whiteColor]];
//    
//    UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(viewController.view.frame.origin.x, viewController.view.frame.origin.y, viewController.view.frame.size.width, 45)];
//    
//    label.text = title;
//    [label setBackgroundColor:[UIColor whiteColor]];
//    [label setFont:[UIFont systemFontOfSize:17]];
//    //    [label setTextColor:[UIColor grayColor]];
//    //文字居中显示
//    label.textAlignment = NSTextAlignmentCenter;
//    //自动折行设置
//    //    label.lineBreakMode = NSLineBreakByWordWrapping;
//    label.numberOfLines = 0;
//    label.adjustsFontSizeToFitWidth = YES;
//    
//    /*自动换行
//     NSDictionary *attribute = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:18] ,NSFontAttributeName, nil];
//     CGSize size = [label.text boundingRectWithSize:CGSizeMake(viewController.view.frame.size.width, 20000.0f) options: NSStringDrawingUsesLineFragmentOrigin   attributes:attribute context:nil].size;
//     [label setFrame:CGRectMake(viewController.view.frame.origin.x, viewController.view.frame.origin.y,size.width,size.height)];
//     */
//    
//    [viewController.view addSubview:label];
//    [label setTranslatesAutoresizingMaskIntoConstraints:NO];
//    [viewController.view addConstraint:[NSLayoutConstraint constraintWithItem:label
//                                                                    attribute:NSLayoutAttributeTop
//                                                                    relatedBy:NSLayoutRelationEqual
//                                                                       toItem:viewController.view
//                                                                    attribute:NSLayoutAttributeTop
//                                                                   multiplier:1 constant:0]];
//    
//    [viewController.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-3.0-[label]-3.0-|" options:0 metrics:Nil views:NSDictionaryOfVariableBindings(label)]];
//    [viewController.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[label(==45)]" options:0 metrics:Nil views:NSDictionaryOfVariableBindings(label)]];
//    
//    
//    UITextView *textView = [[UITextView alloc]init];
//    //    [textView setTextColor:[UIColor grayColor]];
//    [textView setText:content];
//    [textView setEditable:NO];
//    [textView setScrollEnabled:YES];
//    [textView setFont:[UIFont systemFontOfSize:18]];
//    [viewController.view addSubview:textView];
//    [textView setTranslatesAutoresizingMaskIntoConstraints:NO];
//    [viewController.view addConstraint:[NSLayoutConstraint constraintWithItem:textView
//                                                                    attribute:NSLayoutAttributeTop
//                                                                    relatedBy:NSLayoutRelationEqual
//                                                                       toItem:label
//                                                                    attribute:NSLayoutAttributeBottom
//                                                                   multiplier:1
//                                                                     constant:0]];
//    [viewController.view addConstraint:[NSLayoutConstraint constraintWithItem:textView
//                                                                    attribute:NSLayoutAttributeBottom
//                                                                    relatedBy:NSLayoutRelationEqual
//                                                                       toItem:viewController.view
//                                                                    attribute:NSLayoutAttributeBottom
//                                                                   multiplier:1
//                                                                     constant:-5]];
//    [viewController.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[textView]|" options:0 metrics:Nil views:NSDictionaryOfVariableBindings(textView)]];
//    //    [viewController.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[textView(==300)]|" options:0 metrics:Nil views:NSDictionaryOfVariableBindings(textView)]];
//    
//    
//    [self.leveyTabBarController.navigationController pushViewController:viewController animated:YES];
//}



@end
